#include "Row.h"
#include "Block.h"
#include "Configuration.h"
#include "AddBlockToRowNetworkEvent.h"
#include "MoveRowNetworkEvent.h"

Row::Row(long id, int rowNo)
        : GraphicalComposite(id)
{
    setPosition(Position(0, rowNo).scale(Configuration::BLOCK_SIZE));
}

Row::~Row()
{
}

void Row::runFadeOutAnimation(long rowId)
{
    for (Blocks::iterator it = blocks.begin(); it != blocks.end(); ++it)
    {
        (*it)->runFadeOutAnimation(rowId);
    }
}

void Row::handleEvent(const Event& event)
{
    event.visitRow(this);
}

void Row::handleAddBlockToRowEvent(long rowId, const Position& position, const Color& color)
{
    if (rowId == getId())
    {
        Block* block = new Block(position, color);
        blocks.push_back(block);
        addChild(block);
    }
}

void Row::handleMoveRowEvent(long rowId)
{
    if (rowId == getId())
    {
        setPosition(getPosition().move(Position(0, 1).scale(Configuration::BLOCK_SIZE)));
    }
}


